package com.leyou.item.controller;

import com.leyou.item.dto.CategoryDto;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author syf
 * @version 1.0
 * @date 2019/07/30 21:59
 * @Description TODO:分类管理控制器
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     *根据父类的pid查询当前父id下的所有子类
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDto>> findCategoryByPid(@RequestParam("pid") Long pid){

        return ResponseEntity.ok(categoryService.findCategoryByPid(pid));
    }

    /**
     * 根据分类id集合查询分类集合
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDto>> findListById(@RequestParam("ids") List<Long> ids){
        return ResponseEntity.ok(categoryService.findListByIds(ids));
    }
}
